//
// Created by Administrator on 2020/11/29.
//

#ifndef MYNDK_BASECHANNEL_H
#define MYNDK_BASECHANNEL_H
extern "C" {
#include <libavcodec/avcodec.h>
}
#include "SafeQueue.h"
class BaseChannel{
public:
    BaseChannel(int id, AVCodecContext *context,AVRational time_base) : id(id), context(context),time_base(time_base) {
        packets.setReleaseCallback(BaseChannel::releaseAvPacket);
        frames.setReleaseCallback(releaseAvFrame);
    }
    virtual ~BaseChannel(){
        packets.clear();
        frames.clear();
    }


    static void releaseAvPacket(AVPacket** packet){
        if (packet){
            av_packet_free(packet);
            *packet=0;
        }
    }
    static void releaseAvFrame(AVFrame** frame){
        if (frame) {
            av_frame_free(frame);
            //为什么用指针的指针？
            // 指针的指针能够修改传递进来的指针的指向
            *frame = 0;
        }
    }


    virtual void play()=0;

    int id;
    AVCodecContext* context;
    int isPlaying;
    SafeQueue<AVPacket *> packets;
    //解码数据包队列
    SafeQueue<AVFrame *> frames;
    AVRational time_base;

};


#endif //MYNDK_BASECHANNEL_H
